package com.zhongke.cotrun.model.exception;


import com.zhongke.cotrun.model.enums.ErrorCode;

/**
 * <作者 yhl
 * <日期 2018-12-13 14:28
 * 说明 ...
 */
public class BizException extends Exception {

    private int code;
    /**
     * 是否打印栈信息，默认打印
     */
    private boolean printStackInfo = true;

    public BizException() {
        super();
        this.printStackInfo = false;
    }

    /**
     * 异常
     *
     * @param cause
     */
    public BizException(final Throwable cause, final boolean printStackInfo) {
        super(cause);
        this.printStackInfo = printStackInfo;
    }

    /**
     * @param message 错误消息
     */
    public BizException(final String message) {
        super(message);
        this.printStackInfo = false;
    }

    public BizException(final ErrorCode errorCode) {
        super(errorCode.getDesc());
        this.code = errorCode.getCode();
    }

    /**
     * @param errorCode      ErrorCode
     * @param printStackInfo 是否打印栈信息，true 打印, false 不打印
     */
    public BizException(final ErrorCode errorCode, final boolean printStackInfo) {
        super(errorCode.getDesc());
        this.code = errorCode.getCode();
        this.printStackInfo = printStackInfo;
    }

    public BizException(final ErrorCode errorCode, final String message) {
        super(message);
        if (errorCode != null) {
            this.code = errorCode.getCode();
        }
        this.printStackInfo = false;
    }

    public BizException(final ErrorCode errorCode, final String message, final boolean printStackInfo) {
        super(message);
        if (errorCode != null) {
            this.code = errorCode.getCode();
        }
        this.printStackInfo = printStackInfo;
    }

    public BizException(final ErrorCode errorCode, final Throwable cause) {
        super(errorCode == null ? "" : errorCode.getDesc(), cause);

        if (errorCode != null) {
            this.code = errorCode.getCode();
        }
    }

    public BizException(final ErrorCode errorCode, final String message, final Throwable cause) {
        super(message, cause);
        if (errorCode != null) {
            this.code = errorCode.getCode();
        }
    }

    /**
     * @param code 错误消息
     */
    public BizException(final int code) {
        super();
        this.code = code;
        this.printStackInfo = false;
    }

    public BizException(final String message, final Throwable cause) {
        super(message, cause);
    }

    /**
     * @param printStackInfo 是否打印栈信息，true 打印, false 不打印
     * @param message        错误消息
     */
    public BizException(final String message, final Throwable cause, final boolean printStackInfo) {
        super(message, cause);
        this.printStackInfo = printStackInfo;
    }

    /**
     * @param code    错误码
     * @param message 错误消息
     */
    public BizException(final int code, final String message) {
        super(message);
        this.code = code;
        this.printStackInfo = false;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isPrintStackInfo() {
        return printStackInfo;
    }
}

